<!DOCTYPE html>
<!-- saved from url=(0052)http://getbootstrap.com/docs/4.0/examples/dashboard/ -->
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>后台管理</title>
    <!-- Bootstrap core CSS -->
    <link th:href="@{/webjars/bootstrap/4.4.1-1/css/bootstrap.css}" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="asserts/css/dashboard.css" th:href="@{/asserts/css/dashboard.css}" rel="stylesheet">
    <link href="iconfont/iconfont.css" th:href="@{/iconfont/iconfont.css}" rel="stylesheet">
    <link href="asserts/css/from-table.css" th:href="@{/asserts/css/from-table.css}" rel="stylesheet">
    <style type="text/css">
        /* Chart.js */

        @-webkit-keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

        @keyframes chartjs-render-animation {
            from {
                opacity: 0.99
            }
            to {
                opacity: 1
            }
        }

    </style>
</head>

<body>
<!--引入抽取的topbar-->
<!--模板名：会使用thymeleaf的前后缀配置规则进行解析-->
<div th:replace="commons/bar::topbar"></div>

<div class="container-fluid">
    <div class="row">
        <!--引入侧边栏-->
        <div th:replace="commons/bar::#sidebar(activeUri='emps')"></div>

        <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
            <!--需要区分是员工修改还是添加；-->
            <form th:action="@{/emp}" method="post" class="form-range">
                <!--发送put请求修改员工数据-->
                <!--
                1、SpringMVC中配置HiddenHttpMethodFilter;（SpringBoot自动配置好的）
                2、页面创建一个post表单
                3、创建一个input项，name="_method";值就是我们指定的请求方式
                -->
                <input type="hidden" name="_method" value="put" th:if="${emp!=null}"/>
                <input type="hidden" name="EId" th:if="${emp!=null}" th:value="${emp.EId}">
                <div class="title" th:text="${emp!=null}?'修改员工信息':'添加员工信息'">添加员工信息</div>
                <table class="table-css">
                    <tr>
                        <td><span style="color: red">*</span>姓名：</td>
                        <td><input name="name" type="text" class="form-control" placeholder="zhangsan"
                                   th:value="${emp!=null}?${emp.name}" required></td>
                        <div class="table-distance">
                            <td><span style="color: red">*</span>员工工号：</td>
                            <td><input name="workID" type="text" class="form-control" placeholder="ce10***"
                                       th:value="${emp!=null}?${emp.workID}" required></td>
                        </div>
                    </tr>

                    <tr>
                        <td><span style="color: red">*</span>性别：</td>
                        <td>
                            <select class="form-control" name="gender" th:if="${emp==null}" required>
                                <option value="">--请选择--</option>
                                <option th:text="男"></option>
                                <option th:text="女"></option>
                            </select>
                            <select class="form-control" name="gender" th:if="${emp!=null}" required>
                                <option th:selected="${emp.gender eq '男'}" th:text="男"></option>
                                <option th:selected="${emp.gender eq '女'}" th:text="女"></option>
                            </select>
                        </td>
                        <div class="table-distance">
                            <td>年龄：</td>
                            <td><input name="age" id="age" type="text" class="form-control" placeholder="35"
                                       th:value="${emp!=null}?${emp.age}"></td>
                        </div>
                    </tr>

                    <tr>
                        <td></span>出生日期：</td>
                        <td><input name="birthday" type="text" class="form-control" placeholder="1992-01-01"
                                   th:value="${emp!=null}?${#dates.format(emp.birthday, 'yyyy-MM-dd')}" required></td>
                        <div class="table-distance">
                            <td><span style="color: red">*</span>身份证号：</td>
                            <td><input name="IDCard" id="IDCard" type="text" class="form-control" placeholder=""
                                       th:value="${emp!=null}?${emp.IDCard}" required></td>
                        </div>
                    </tr>

                    <tr>
                        <td>婚姻状况：</td>
                        <td>
                            <select class="form-control" name="wedlock" th:if="${emp==null}">
                                <option  th:text="未婚"></option>
                                <option  th:text="已婚"></option>
                                <option  th:text="离异"></option>
                            </select>
                            <select class="form-control" name="wedlock" th:if="${emp!=null}">
                                <option th:selected="${emp.wedlock} eq '未婚'" th:text="未婚"></option>
                                <option th:selected="${emp.wedlock} eq '已婚'" th:text="已婚"></option>
                                <option th:selected="${emp.wedlock} eq '离异'" th:text="离异"></option>
                            </select>
                        </td>
                        <div class="table-distance">
                            <td>民族：</td>
                            <!--提交的是民族的id-->
                            <td>
                                <select class="form-control" name="nationId" id="nation">
                                    <option value="">--请选择--</option>
                                    <option th:selected="${emp!=null}?${nation.id == emp.nationId}"
                                            th:value="${nation.id}" th:each="nation:${nations}"
                                            th:text="${nation.name}"></option>
                                </select>
                            </td>
                        </div>
                    </tr>

                    <tr>
                        <td>籍贯：</td>
                        <td colspan="2"><input name="nativePlace" type="text" class="form-control" placeholder=""
                                               th:value="${emp!=null}?${emp.nativePlace}"></td>
                    </tr>

                    <tr>
                        <td>邮箱：</td>
                        <td><input name="email" type="email" class="form-control" placeholder="zhangsan@163.com"
                                   th:value="${emp!=null}?${emp.email}"></td>
                        <div class="table-distance">
                            <td>联系电话：</td>
                            <td><input name="phone" type="text" class="form-control" placeholder=""
                                       th:value="${emp!=null}?${emp.phone}"></td>
                        </div>
                    </tr>

                    <tr>
                        <td><span style="color: red">*</span>联系地址：</td>
                        <td colspan="3"><input name="address" type="text" class="form-control" placeholder=""
                                               th:value="${emp!=null}?${emp.address}" required></td>
                    </tr>
                    <tr>
                        <td><span style="color: red">*</span>所属部门：</td>
                        <!--提交的是部门的id-->
                        <td><select class="form-control" name="deptId" id="sel_dept" required>
                            <option value="">--请选择--</option>
                            <option  th:value="${dept.id}" th:each="dept:${depts}" th:text="${dept.name}" th:selected="${emp!=null}?${dept.id == emp.deptId}" ></option>
                        </select>
                        </td>
                        <div class="table-distance" >
                            <td><span style="color: red">*</span>职位：</td>
                            <!--提交的是职位的id-->
                            <td>
                                <select class="form-control" name="posId" id="sel_pos" required>
                                    <option value="">--请选择--</option>
                                   <span th:if="${emp!=null}">
                                       <option  th:selected="${emp!=null}?${position.id == emp.posId}"
                                                th:value="${position.id}"  th:each="position:${positions}"
                                                th:unless="${position.did}!=${emp.deptId}" th:text="${position.name}"  ></option>
                                   </span>

                                </select>
                            </td>
                        </div>
                    </tr>

                    <tr>
                        <td>毕业院校：</td>
                        <td><input name="school" type="text" class="form-control" placeholder=""
                                   th:value="${emp!=null}?${emp.school}"></td>
                        <div class="table-distance">
                            <td><span style="color: red">*</span>学历：</td>
                            <td>
                                <select class="form-control" name="degree" th:if="${emp==null}" required>
                                    <option value="">--请选择--</option>
                                    <option th:text="博士"></option>
                                    <option th:text="硕士"></option>
                                    <option th:text="本科"></option>
                                    <option th:text="大专"></option>
                                    <option th:text="高中"></option>
                                    <option th:text="初中"></option>
                                    <option th:text="小学"></option>
                                    <option th:text="其他"></option>
                                </select>
                                <select class="form-control" name="degree" th:if="${emp!=null}" required>
                                    <option th:selected="${emp.degree} eq '博士'"  th:text="博士"></option>
                                    <option th:selected="${emp.degree} eq '硕士'"  th:text="硕士"></option>
                                    <option th:selected="${emp.degree} eq '本科'"  th:text="本科"></option>
                                    <option th:selected="${emp.degree} eq '大专'"  th:text="大专"></option>
                                    <option th:selected="${emp.degree} eq '高中'"  th:text="高中"></option>
                                    <option th:selected="${emp.degree} eq '初中'"  th:text="初中"></option>
                                    <option th:selected="${emp.degree} eq '小学'"  th:text="小学"></option>
                                    <option th:selected="${emp.degree} eq '其他'"  th:text="其他"></option>
                                </select>
                            </td>
                        </div>
                    </tr>

                    <tr>
                        <td><span style="color: red">*</span>入职日期：</td>
                        <td><input name="workDate" type="text" class="form-control" placeholder=""
                                   th:value="${emp!=null}?${#dates.format(emp.workDate, 'yyyy-MM-dd')}" required></td>
                     <!--   <div class="table-distance">
                            <td>转正日期：</td>
                            <td><input name="conversionTime" type="text" class="form-control" placeholder=""
                                       th:value="${emp!=null}?${#dates.format(emp.conversionTime, 'yyyy-MM-dd')}"></td>
                        </div>-->
                    </tr>

                    <tr>
                        <td><span style="color: red">*</span>在职状态：</td>
                        <td>
                            <select class="form-control" name="workState" th:if="${emp==null}" required>
                                <option value="">--请选择--</option>
                                <option th:text="在职"></option>
                                <option th:text="离职"></option>
                            </select>
                            <select class="form-control" name="workState" th:if="${emp!=null}" required>
                                <option th:selected="${emp.workState} eq '在职'" th:text="在职"></option>
                                <option th:selected="${emp.workState} eq '离职'" th:text="离职"></option>
                            </select>
                        </td>
                        <div class="table-distance">
                            <td>离职日期：</td>
                            <td><input name="notWorkDate" type="text" class="form-control" placeholder=""
                                       th:value="${emp!=null}?${#dates.format(emp.notWorkDate, 'yyyy-MM-dd')}"></td>
                            <!--<td>工龄：</td>
                            <td><input name="workAge" type="text" class="form-control" placeholder=""
                                       th:value="${emp!=null}?${emp.workAge}"></td>-->
                        </div>
                    </tr>

                </table>
                <div class="range-bottom">
                    <button type="submit" id="button" class="btn btn-primary" th:text="${emp!=null}?'修改':'确认'"></button>
                    <a th:href="@{/emps}" class="btn btn-info" role="button">返回</a>
                </div>
                <div class="range-care">注：带红色*号为必填选项</div>
            </form>
        </main>
    </div>
</div>

<script type="text/javascript" th:src="@{/webjars/jquery/3.5.0/jquery.js}"></script>
<script th:inline="javascript">

    $("#sel_dept").bind("change", function () {
        $('#sel_pos option').not(":first").remove();
        $.ajax({
            url: '/cems/emp/pos',
            data: {
                id: $("#sel_dept").val()
            },
            success: function (d) {
                if (d) {
                    var data = d;
                    console.log(data);
                    for (var i in data) {
                        /*循环添加option*/
                        $("#sel_pos:last").append("<option value=" + data[i].id + ">" + data[i].name + "</option>")
                    }
                }
            }
        })
    });


</script>

</body>

</html>
